{%extends "admin/base.html"%}
{% load i18n %}

{%block content%}
<div>
	<h2 class="title1">{% trans "Categories" %}</h2>
	{% if messages %}
	<ul class="messages">
		{% for message in messages %}
		<li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
		{% endfor %}
	</ul>
	{% endif %}
	<div id="col-container">
		<div id="col-left">
			<h3>{% if id %}{% trans "Edit category" %}
				{% else %}{% trans "Add category" %}{% endif %}</h3>
			<form method="post" action="{{ blog.get_admin_add_category_url }}" class="full-width">
				<div>
					{{ categoryform.id }}
					{{ categoryform.blog }}
					{{ categoryform.type }}
				</div>
				<div class="form-field">
					{{ categoryform.title.label_tag }}<span class="red">*</span>
					{{ categoryform.title }}
					{% if categoryform.title.errors %}{{ categoryform.title.errors }}
				    {% endif %}
				</div>
				<div class="form-field">
					{{ categoryform.slug.label_tag }}<span class="red">*</span>
					{{ categoryform.slug }}
					{% if categoryform.slug.errors %}{{ categoryform.slug.errors }}
				    {% endif %}
				</div>
				<div class="form-field">
					{{ categoryform.parent.label_tag }}
					{{ categoryform.parent }}
					{% if categoryform.parent.errors %}{{ categoryform.parent.errors }}
				    {% endif %}
				</div>
				<div class="form-field">
					<input type="hidden" id="ordered_values" name="ordered_values" />
					{{ categoryform.order }}
					<label for="display_orders">{% trans "Display order" %}</label>
					<br/>
					<table width="80%">
						<tr>
							<td style="border: 0px;">
								<select id="display_orders" onfocus="this.defOpt=this.selectedIndex" 
									onchange="this.selectedIndex=this.defOpt;" size="10" name="display_orders"
									style="width: 100%;">
									{% for category in category_list %}
									<option {% ifequal id category.id %}selected{% endifequal %}
										value={{ category.id }}>{{ category.title }}</option>
									{% endfor %}
									{% if not id %}
									<option selected value="0">{% trans "New category" %}</option>
									{% endif %}
								</select>
							</td>
							<td style="width: 20px">
								<label for="display_orders">
									<table>
										<tr><td style="text-align: right;">
											<img src="/static/images/arrow-up.png" style="cursor: pointer;"
												onclick="senbz.operation.move_select('display_orders', false, 'ordered_values')" /></td>
										</tr>
										<tr><td style="text-align: right;">
											<img src="/static/images/arrow-down.png" style="cursor: pointer;"
												onclick="senbz.operation.move_select('display_orders', true, 'ordered_values')" /></td>
										</tr>
									</table>
								</label>
							</td>
						</tr>
					</table>
				</div>
				<div class="form-field">
					{{ categoryform.show_in_navigation.label_tag }}
					{{ categoryform.show_in_navigation }}
					{% if categoryform.show_in_navigation.errors %}{{ categoryform.show_in_navigation.errors }}
					{% endif %}
				</div>
				<div class="form-field">
				    {{ categoryform.description.label_tag }}
					{{ categoryform.description }}
				    {% if categoryform.description.errors %}
				    	{{ categoryform.description.errors }}
				    {% endif %}
				</div>
				<p><input class="button" name="submit" 
					value="{%if id%}{%trans 'Edit category'%}{%else%}{%trans 'Add category' %}{%endif%}"
					type="submit"></p>
			</form>
		</div>
		<div id="col-right">
			<div class="col-wrap">
				<form id="posts-filter" action="{{ blog.get_admin_delete_category_url }}" method="post">
					<div class="tablenav">
						<div>
							<select name="action">
								<option value="" selected="selected">{% trans "Batch" %}</option>
								<option value="delete">{% trans "Delete" %}</option>
							</select>
							<input value="{% trans 'Apply' %}" class="submit button" type="submit">
						</div>
					</div>
					<div class="clear"></div>
					<table class="list" cellspacing="0">
						<thead>
							<tr>
								<th id="cb" class="check-column">
									<input type="checkbox" 
										onclick="$('input[name=checks]').attr('checked',this.checked);"></th>
								<th>{% trans "Name" %}</th>
								<th>{% trans "Created date" %}</th>
								<th style="width: 70px;" class="num">{% trans "Articles count" %}</th>
								<th>{% trans "Category description" %}</th>
							</tr>
						</thead>
						<tfoot>
							<tr>
								<th class="check-column">
									<input type="checkbox" 
										onclick="$('input[name=checks]').attr('checked',this.checked);"></th>
								<th>{% trans "Name" %}</th>
								<th>{% trans "Created date" %}</th>
								<th class="num">{% trans "Articles count" %}</th>
								<th>{% trans "Category description" %}</th>
							</tr>
						</tfoot>
						<tbody>
							{% if categories.object_list %}
							{% for cat in categories.object_list %}
							<tr>
								<th class="check-column"> 
									<input name="checks" value="{{cat.id}}" type="checkbox"></th>
								<td>
									<strong>
										<a class="row-title" href="{{ cat.get_admin_show_category_url }}" 
											title="{% trans 'Edit' %} &quot;{{ cat.title }}&quot;">
											{{cat.title}}</a>
									</strong>
								</td>
								<td>
									{{ cat.created_date|date:"Y-m-d" }}
								</td>
								<td class="num">{{ cat.article_set.count }}</td>
								<td>{{ cat.description }}</td>
							</tr>
							{%endfor%}
							{%else%}
							<tr>
								<td colspan="6" align="center" style="font-size: 16px;">{% trans "No category" %}</td>
							</tr>
							{%endif%}
						</tbody>
					</table>
					<div class="tablenav">
						<div class="pagination">
						    <span class="step-links">
			                    {% if categories.has_previous %}
			                    <a href="?page={{ categories.previous_page_number }}">previous</a>
			                    {% endif %}
			                    {% for page in categories_page_range %}
			                        {% ifequal page categories.number %}
			                        <span>{{ page }}</span>
			                        {% else %}
			                        <a href="?page={{ page }}">{{ page }}</a>
			                        {% endifequal %}
			                    {% endfor %}
			                    {% if categories.has_next %}
			                        <a href="?page={{ categories.next_page_number }}">next</a>
			                    {% endif %}
						        <span class="current">
						            Page {{ categories.number }} of {{ categories.paginator.num_pages }}.
						        </span>
						    </span>
						</div>
					</div>
					<br class="clear">
				</form>
			</div>
		</div>
	</div>
</div>
{%endblock%}